﻿using System;
using System.Collections.Generic;
using BDPAutodetect.DataServicePm.ModelPostgreSQL;
using Microsoft.EntityFrameworkCore;

namespace BDPAutodetect.DataServicePm.ContextPostgreSQL;

public partial class CoreDBContext : DbContext
{
    public CoreDBContext()
    {
    }

    public CoreDBContext(DbContextOptions<CoreDBContext> options)
        : base(options)
    {
    }

    public virtual DbSet<TBasicPower> TBasicPowers { get; set; }

    public virtual DbSet<TBasicRole> TBasicRoles { get; set; }

    public virtual DbSet<TBasicRprelation> TBasicRprelations { get; set; }

    public virtual DbSet<TBasicSlave> TBasicSlaves { get; set; }

    public virtual DbSet<TBasicStation> TBasicStations { get; set; }

    public virtual DbSet<TBasicSystem> TBasicSystems { get; set; }

    public virtual DbSet<TBasicTarget> TBasicTargets { get; set; }

    public virtual DbSet<TBasicUser> TBasicUsers { get; set; }

    public virtual DbSet<TDetectRecordDatum> TDetectRecordData { get; set; }

    public virtual DbSet<TDetectRecordTotal> TDetectRecordTotals { get; set; }

    public virtual DbSet<TParameter> TParameters { get; set; }

    public virtual DbSet<TParameterLimit> TParameterLimits { get; set; }

    public virtual DbSet<TTargetSlave> TTargetSlaves { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
        => optionsBuilder.UseNpgsql("Server=127.0.0.1;Port=5432;User Id=postgres;Password=123456;Database=bdpautodetect;Enlist=true");

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<TBasicPower>(entity =>
        {
            entity.ToTable("T_Basic_Power");

            entity.HasIndex(e => e.Name, "UQ_T_Basic_Power").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Inco).HasColumnType("character varying");
            entity.Property(e => e.MenuStatus).HasDefaultValue(0);
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.ParentId)
                .HasDefaultValue(0)
                .HasColumnName("ParentID");
            entity.Property(e => e.TreeStatus).HasDefaultValue(0);
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
            entity.Property(e => e.Url)
                .HasColumnType("character varying")
                .HasColumnName("URL");
        });

        modelBuilder.Entity<TBasicRole>(entity =>
        {
            entity.ToTable("T_Basic_Role");

            entity.HasIndex(e => e.Name, "UQ_T_Basic_Role").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.Supered).HasDefaultValue(0);
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicRprelation>(entity =>
        {
            entity.ToTable("T_Basic_RPRelation");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Permission).HasDefaultValue(0);
            entity.Property(e => e.PowerId)
                .HasDefaultValue(0)
                .HasColumnName("PowerID");
            entity.Property(e => e.RoleId)
                .HasDefaultValue(0)
                .HasColumnName("RoleID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicSlave>(entity =>
        {
            entity.ToTable("T_Basic_Slave");

            entity.HasIndex(e => e.Name, "UQ_T_Basic_Slave").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.NameNick).HasColumnType("character varying");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicStation>(entity =>
        {
            entity.ToTable("T_Basic_Station");

            entity.HasIndex(e => e.Code, "UQ_T_Basic_Station").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Code).HasColumnType("character varying");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicSystem>(entity =>
        {
            entity.ToTable("T_Basic_Systems");

            entity.HasIndex(e => e.Name, "UQ_T_Basic_Systems").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.DataType).HasDefaultValue(0);
            entity.Property(e => e.Datum).HasColumnType("character varying");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicTarget>(entity =>
        {
            entity.ToTable("T_Basic_Target");

            entity.HasIndex(e => e.Code, "UQ_T_Basic_Target").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Category).HasDefaultValue(0);
            entity.Property(e => e.Code).HasColumnType("character varying");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TBasicUser>(entity =>
        {
            entity.ToTable("T_Basic_User");

            entity.HasIndex(e => e.Name, "UQ_T_Basic_User").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Freezed).HasDefaultValue(0);
            entity.Property(e => e.Logined).HasDefaultValue(0);
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.NameNick).HasColumnType("character varying");
            entity.Property(e => e.Password).HasColumnType("character varying");
            entity.Property(e => e.RoleId)
                .HasDefaultValue(0)
                .HasColumnName("RoleID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TDetectRecordDatum>(entity =>
        {
            entity.ToTable("T_DetectRecord_Data");

            entity.HasIndex(e => new { e.SampleDateTime, e.StationId, e.ParameterId, e.StatusFlag }, "IN_T_DetectRecord_Data");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Barcode).HasColumnType("character varying");
            entity.Property(e => e.DebugModeStart).HasColumnType("character varying");
            entity.Property(e => e.Ntctemperature).HasColumnName("NTCTemperature");
            entity.Property(e => e.ParameterId)
                .HasDefaultValue(0)
                .HasColumnName("ParameterID");
            entity.Property(e => e.SampleDateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
            entity.Property(e => e.SampleDuration).HasDefaultValue(0);
            entity.Property(e => e.SoftwareVersion).HasColumnType("character varying");
            entity.Property(e => e.StationId)
                .HasDefaultValue(0)
                .HasColumnName("StationID");
            entity.Property(e => e.StatusFlag).HasDefaultValue(0);
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
            entity.Property(e => e.UserId)
                .HasDefaultValue(0)
                .HasColumnName("UserID");
            entity.Property(e => e.WitchBarrelMicro).HasColumnType("character varying");
            entity.Property(e => e.WitchTipping).HasColumnType("character varying");
        });

        modelBuilder.Entity<TDetectRecordTotal>(entity =>
        {
            entity.ToTable("T_DetectRecord_Total");

            entity.HasIndex(e => e.StationId, "IN_T_DetectRecord_Total");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.DetectCount).HasDefaultValue(0);
            entity.Property(e => e.DetectDuration).HasDefaultValue(0);
            entity.Property(e => e.StationId)
                .HasDefaultValue(0)
                .HasColumnName("StationID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TParameter>(entity =>
        {
            entity.ToTable("T_Parameter");

            entity.HasIndex(e => new { e.SlaveId, e.Name }, "UQ_T_Parameter").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Name).HasColumnType("character varying");
            entity.Property(e => e.SlaveId)
                .HasDefaultValue(0)
                .HasColumnName("SlaveID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TParameterLimit>(entity =>
        {
            entity.ToTable("T_Parameter_Limit");

            entity.HasIndex(e => new { e.ParameterId, e.TargetId }, "UQ_T_Parameter_Limit").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Limit).HasColumnType("character varying");
            entity.Property(e => e.LimitTime).HasDefaultValue(0);
            entity.Property(e => e.LimitTo).HasColumnType("character varying");
            entity.Property(e => e.ParameterId)
                .HasDefaultValue(0)
                .HasColumnName("ParameterID");
            entity.Property(e => e.TargetId)
                .HasDefaultValue(0)
                .HasColumnName("TargetID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        modelBuilder.Entity<TTargetSlave>(entity =>
        {
            entity.ToTable("T_Target_Slave");

            entity.HasIndex(e => new { e.StationId, e.SlaveId, e.TargetId, e.Category }, "UQ_T_Target_Slave").IsUnique();

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.Category).HasDefaultValue(0);
            entity.Property(e => e.CheckCommand).HasColumnType("character varying");
            entity.Property(e => e.CheckMode).HasDefaultValue(0);
            entity.Property(e => e.DataType).HasDefaultValue(0);
            entity.Property(e => e.DataUnit).HasDefaultValue(0);
            entity.Property(e => e.DetectWaitFlag).HasDefaultValue(0);
            entity.Property(e => e.DisplayUnit).HasDefaultValue(0);
            entity.Property(e => e.PermissionFlag).HasDefaultValue(0);
            entity.Property(e => e.RegisterAddress).HasDefaultValue(0);
            entity.Property(e => e.SendWaitFlag).HasDefaultValue(0);
            entity.Property(e => e.SlaveAddress).HasDefaultValue(0);
            entity.Property(e => e.SlaveCommand).HasColumnType("character varying");
            entity.Property(e => e.SlaveFuncCode).HasDefaultValue(0);
            entity.Property(e => e.SlaveId)
                .HasDefaultValue(0)
                .HasColumnName("SlaveID");
            entity.Property(e => e.StationId)
                .HasDefaultValue(0)
                .HasColumnName("StationID");
            entity.Property(e => e.TargetId)
                .HasDefaultValue(0)
                .HasColumnName("TargetID");
            entity.Property(e => e.TargetMapId)
                .HasDefaultValue(0)
                .HasColumnName("TargetMapID");
            entity.Property(e => e.UpdateTime)
                .HasDefaultValueSql("now()")
                .HasColumnType("timestamp without time zone");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
